
package finalproject.client;

import java.util.List;

import finalproject.shared.Student;
import finalproject.shared.Vak;
import finalproject.shared.Absentie;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;


public class AbsentieClass {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    AbsentieGui gui;
    //dhdhdhddhdh

    void listAbsenties() {
    	
    	// verzamel de aanwezige studenten voor de gui
    	projectService.listStudenten(new AsyncCallback<List<Student>> () {
                    public void onFailure(Throwable caught) {     	
                    	List<Student> result = null;
                    	gui.service_studentenListRetrievedFromService(result);
                    }
        
                    public void onSuccess(List<Student> result) {
                        gui.service_studentenListRetrievedFromService(result);
                    }
        }
        );    	

       	// verzamel de aanwezige vakken
        projectService.listVakken(new AsyncCallback<List<Vak>> () {
                    public void onFailure(Throwable caught) {
                    	List<Vak> result = null;
                    	gui.service_vakkenListRetrievedFromService(result);
                    }
        
                    public void onSuccess(List<Vak> result) {
                        gui.service_vakkenListRetrievedFromService(result);
                        
                    }
        }
        );  	
    	
        projectService.listAbsenties(new AsyncCallback<List<Absentie>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListAbsentiesFailed(caught);
                    }
        
                    public void onSuccess(List<Absentie> result) {
                        gui.service_absentiesListRetrievedFromService(result);
                        
                    }
        }
        );
    }
    
    void addAbsentie(final Absentie absentie) {
       projectService.addAbsentie(absentie, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddAbsentieFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddAbsentieSuccessful();
            }
        }
        );     
    }

  
    void updateAbsentie(final Absentie absentie) {
        projectService.updateAbsentie(absentie, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateAbsentieFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateAbsentieSuccessful();
            }
        }
        );       
    }

   
    void removeAbsentie(final Absentie absentie) {
        projectService.removeAbsentie(absentie, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveAbsentieFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveAbsentieSuccessful();
            }
        }
        );       
    }
    
}